package com.hngy.xpq.android_practice.merchant_main.Comm;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.hngy.xpq.android_practice.R;
import com.hngy.xpq.android_practice.database.SQLiteComm;

import java.io.ByteArrayOutputStream;

public class Comm_image extends AppCompatActivity {

    private int[] icon = new int[]{R.drawable.hmj,R.drawable.xlx,R.drawable.jxdf,R.drawable.lzj,R.drawable.gljr,R.drawable.mfcb,R.drawable.sndx,R.drawable.ymyt,R.drawable.myls};

    GridView avatar;
    SQLiteComm sqLiteComm;
    SharedPreferences notification;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.comm_image);

        sqLiteComm = new SQLiteComm(this);
        avatar = findViewById(R.id.comm_images);
        BaseAdapter baseAdapter = new BaseAdapter() {
            @Override
            public int getCount() {
                return icon.length;
            }

            @Override
            public Object getItem(int position) {
                return position;
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView imageView;
                if (convertView == null){
                    imageView = new ImageView(Comm_image.this);
                    imageView.setAdjustViewBounds(true);
                    imageView.setMaxWidth(158);
                    imageView.setMaxHeight(150);
                    imageView.setPadding(5, 5, 5, 5);
                } else {
                    imageView = (ImageView) convertView;
                }
                imageView.setImageResource(icon[position]);
                return imageView;
            }
        };
        avatar.setAdapter(baseAdapter);
        avatar.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = getIntent();
                Bundle bundle = new Bundle();
                bundle.putInt("icon",icon[position]);
                intent.putExtras(bundle);
                setResult(0x15, intent);
                finish();
            }
        });
    }
}